Previous Book Contents Book Index Next

Inside Macintosh: 3D Graphics Programming With QuickDraw 3D /
Chapter 5 - Attribute Objects


About Attribute Objects

An attribute object (or, more briefly, an attribute) is a type of QuickDraw 3D object that determines some of the characteristics of a model, such as the color of objects or parts of objects in the model, the transparency of objects, and so forth. In general, attributes define material properties of the surfaces of objects in a model.

An attribute is defined as an attribute type and some associated data. You apply an attribute to an object by creating an instance of a specific attribute type, defining its data, and then attaching it to the object. QuickDraw 3D defines many types of attributes, including diffuse color, specular color, transparency color, surface normals, and surface tangents.

In general, however, attributes are not applied to objects individually. Instead, you usually create an attribute set, which is a collection of zero or more different attribute types and their associated data. For example, to create a transparent red triangle, you create an attribute set, add both color and transparency attributes to it, and then attach the attribute set to the triangle. An attribute set is of type TQ3AttributeSet, a type of TQ3SetObject.

Types of Attributes and Attribute Sets

QuickDraw 3D defines a large number of basic attribute types, which represent information such as surface color, transparency, parameterization, normal, tangent, and so forth. In addition, if the basic QuickDraw 3D attribute types are not sufficient for the needs of your application, you can define custom attribute types. For example, you might want to maintain information about the temperature over time of each point on the surface of an object. To do so, you can define a new attribute type and a data structure to hold the relevant information. You also need to define an attribute metahandler, which contains methods for handling your custom attribute data. (QuickDraw 3D defines metahandlers for all the basic attribute types.)

The basic attributes types are defined by constants. See "Attribute Types" on page 5-14 for a complete description of these attribute types.

typedef enum TQ3AttributeTypes {
   kQ3AttributeTypeNone                            = 0,
   kQ3AttributeTypeSurfaceUV                       = 1,
   kQ3AttributeTypeShadingUV                       = 2,
   kQ3AttributeTypeNormal                          = 3,
   kQ3AttributeTypeAmbientCoefficient              = 4,
   kQ3AttributeTypeDiffuseColor                    = 5,
   kQ3AttributeTypeSpecularColor                   = 6,
   kQ3AttributeTypeSpecularControl                 = 7,
   kQ3AttributeTypeTransparencyColor               = 8,
   kQ3AttributeTypeSurfaceTangent                  = 9,
   kQ3AttributeTypeHighlightState                  = 10,
   kQ3AttributeTypeSurfaceShader                   = 11
} TQ3AttributeTypes;
You can attach a set of attributes to a view, to a group of objects, to a single geometric object, to a face of an object, or to a vertex of an object. In addition, you can attach edge and corner attributes to meshes. For each of these levels, QuickDraw 3D defines a set of natural attributes. For example, the surface normal attribute (which defines the normal vector at a point) makes no sense when applied to a view or a nonpolygonal geometric object. It does, however, make sense to include the surface normal attribute in a set of face or vertex attributes. Accordingly, the surface normal attribute is contained in the natural sets of attributes for faces and vertices, but not for views, groups, or nonpolygonal geometric objects. Table 5-1 lists the natural attributes that can be assigned to objects in the QuickDraw 3D object hierarchy.

IMPORTANT
You can, if you wish, include in the attribute set of any kind of object attributes that are not natural to that object. For instance, you can put a surface normal attribute into an attribute set attached to a view. You can then access that unnatural attribute in precisely the same way you access any other attribute in the set. The only difference between natural and unnatural attributes is that unnatural attributes in an attribute set are not inherited by objects lower down in the class hierarchy. See "Attribute Inheritance" on page 5-6 for details.
Natural sets of attributes for objects in a hierarchy
Object typeNatural attributes in the set
View object
Group object
Geometric object
Face
kQ3AttributeTypeAmbientCoefficient
kQ3AttributeTypeDiffuseColor
kQ3AttributeTypeSpecularColor
kQ3AttributeTypeSpecularControl
kQ3AttributeTypeTransparencyColor
kQ3AttributeTypeHighlightState
kQ3AttributeTypeSurfaceShader
VertexkQ3AttributeTypeSurfaceUV
kQ3AttributeTypeShadingUV
kQ3AttributeTypeNormal
kQ3AttributeTypeAmbientCoefficient
kQ3AttributeTypeDiffuseColor
kQ3AttributeTypeSpecularColor
kQ3AttributeTypeSpecularControl
kQ3AttributeTypeTransparencyColor
kQ3AttributeTypeSurfaceTangent
Note
Surface normals assigned to faces are ignored by renderers, as are the surface normals that are computed geometrically from the points that make up the face.

Attribute Inheritance

During the rendering of the objects in a view, attribute sets of objects higher in the view hierarchy are inherited by objects below them. For example, if the attribute set of a view specifies a particular diffuse color, then all objects in that view are rendered with that diffuse color, unless some other attribute set overrides the color specified in the view attributes. That is, if some face of some object has an attribute set containing a different diffuse color, the face's diffuse color overrides the diffuse color that otherwise would have been inherited from the view attribute set.

Attribute inheritance always occurs in this order:

  1. view
  2. group
  3. geometric object
  4. face
  5. mesh edge
  6. vertex
  7. mesh corner

In other words, view attributes are always inherited by all groups of objects in the model, unless a group contains overriding attributes. Similarly, any attributes assigned to a geometric object are inherited by all faces of the object, unless a face contains overriding attributes.

This attribute inheritance applies only to the natural attributes contained in any attribute set. If, for example, an attribute set of a view contains a surface normal attribute (which is not a natural attribute for view attribute sets), that attribute is not inherited by any objects lower down in the hierarchy.

If you define a custom attribute, you can specify whether you want that attribute to be inherited along the attribute inheritance path by including an attribute inheritance method in your attribute metahandler. See "Defining Custom Attribute Types" on page 5-9 for a sample attribute metahandler that specifies that the temperature attribute is to be inherited. If you do not supply an attribute inheritance method, QuickDraw 3D assumes you want no such inheritance for your custom attribute.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996